package com.millstein.vo;

import cn.hutool.core.collection.CollectionUtil;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * @description:
 * @author: tsing
 * @create: 2021-09-16 22:23
 */
@Data
public class CartVO {
    // 购物车中的商品信息
    @JsonProperty("cart_item_list")
    private List<CartItemVO> cartItemList;
    // 总数量
    @JsonProperty("total_count")
    private Integer totalCount;
    // 总金额
    @JsonProperty("total_amount")
    private BigDecimal totalAmount;
    // 实际支付金额
    @JsonProperty("actual_amount")
    private BigDecimal actualAmount;

    public Integer getTotalCount() {
        if (CollectionUtil.isEmpty(cartItemList)) {
            return 0;
        }
        return this.cartItemList.stream().mapToInt(CartItemVO::getBuyNum).sum();
    }

    public BigDecimal getTotalAmount() {
        BigDecimal totalAmount = BigDecimal.ZERO;
        if (CollectionUtil.isNotEmpty(cartItemList)) {
            for (CartItemVO cartItemVO : cartItemList) {
                totalAmount = cartItemVO.getTotalAmount().add(totalAmount);
            }
        }
        return totalAmount;
    }

    /**
     * 暂时返回和总价一样
     * @return
     */
    public BigDecimal getActualAmount() {
        return this.getTotalAmount();
    }
}
